In [1]:
%load_ext autoreload

In [2]:
%autoreload 2

In [3]:
%aimport vector

In [4]:
from vector import *

Quiz: Plus, Minus, Scalar Multiply


In [5]:
v = Vector([1,2,3])
w = Vector([2,3,4])
print v.plus(w)


Vector: {3.000, 5.000, 7.000}

Quiz: Maginitude & Direction


In [6]:
v = Vector([-0.221, 7.437])
print v.magnitude()
v = Vector([8.813, -1.331, -6.247])
print v.magnitude()
v = Vector([5.581, -2.136])
print v.normalized()
v = Vector([1.996, 3.108, -4.554])
print v.normalized()


7.4402829247280646285389593685977160930633544921875
10.8841875672922885343041343730874359607696533203125
Vector: {0.934, -0.357}
Vector: {0.340, 0.530, -0.777}

Quiz: Coding Dot Product & Angle


In [7]:
from vector import *

v = Vector([7.887, 4.138])
w = Vector([-8.802, 6.776])
print v.dot(w)

v = Vector([-5.955, -4.904, -1.874])
w = Vector([-4.496, -8.755, 7.103])
print v.dot(w)

v = Vector([3.183, -7.627])
w = Vector([-2.668, 5.319])
print v.angle(w)

v = Vector([7.35, 0.221, 5.188])
w = Vector([2.751, 8.259, 3.985])
print v.angle(w, True)


-41.38228599999999454398391663
56.39717800000000569975711073
3.07202630984
60.2758112052

Checking Parallel, Orthogonal


In [8]:
from vector import *

v = Vector([-7.579, -7.88])
w = Vector([22.737, 23.64])
print v.is_parallel(w)
print v.is_orthogonal(w)

v = Vector([-2.029, 9.97, 4.172])
w = Vector([-9.231, -6.639, -7.245])
print v.is_parallel(w)
print v.is_orthogonal(w)

v = Vector([-2.328, -7.284, -1.214])
w = Vector([-1.821, 1.072, -2.94])
print v.is_parallel(w)
print v.is_orthogonal(w)

v = Vector([2.118, 4.827])
w = Vector([0, 0])
print v.is_parallel(w)
print v.is_orthogonal(w)


True
False
False
False
False
True
True
True

Quiz: Coding Vector Projects


In [9]:
from vector import *

v = Vector([3.039, 1.879])
b = Vector([0.825, 2.036])
print v.parallel_project(b)

v = Vector([-9.88, -3.264, -8.159])
b = Vector([-2.155, -9.352, -9.473])
print v.orthogonal_project(b)

v = Vector([3.009, -6.172, 3.692, -2.51])
b = Vector([6.404, -9.144, 2.759, 8.718])
print v.parallel_project(b)
print v.orthogonal_project(b)


Vector: {1.083, 2.672}
Vector: {-8.350, 3.376, -1.433}
Vector: {1.969, -2.811, 0.848, 2.680}
Vector: {1.040, -3.361, 2.844, -5.190}

Quiz: Coding Cross Products


In [10]:
from vector import *

v = Vector([8.462, 7.893, -8.187])
w = Vector([6.984, -5.975, 4.778])
print v.cross(w)

v = Vector([-8.987, -9.838, 5.031])
w = Vector([-4.268, -1.861, -8.866])
print v.area_parallelogram(w)

v = Vector([1.5, 9.547, 3.691])
w = Vector([-6.007, 0.124, 5.772])
print v.area_triangle(w)


Vector: {-11.205, -97.609, -105.685}
142.1222214018463319007423706352710723876953125
42.56493739941893750255985651